/**
 * 
 */
package leilib.ir.crawler.pages;

import java.util.Random;

/**
 * @author LeilibPC
 * 
 */
public class TestPageQueueBlocking {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		final PagesQueue<String> queue = new PagesQueue<String>(1);

		// int count = 0;

		for (int i = 0; i < 3; i++) {
			new Thread(new Runnable() {
				public void run() {
					while (true) {
						String name = Thread.currentThread().getName();
						println(name + "putting...");
						String s = "Content:" + new Random().nextInt(100);
						queue.put(s);
						println(name + "Put" + s);
						println("|" + queue.size());
					}
				}
			}).start();
		}

		for (int i = 0; i < 3; i++) {
			new Thread(new Runnable() {
				public void run() {
					while (true) {
						String name = Thread.currentThread().getName();
						println(name + "taking...");
						String conent = queue.take(1000);
						println(name + "Take:" + conent);
						println("|" + queue.size());
					}
				}
			}).start();
		}
	}

	public static void println(String s) {
		System.out.println(s);
	}

}
